package com.webc.framework.config;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @author hejianglong
 * @date 2018/9/6.
 */
public class Resource {

    private final static String configFilename = "application.properties";

    private static Properties resourceProperties = null;

    static {
        try {
            resourceProperties = loadProperties(configFilename);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static String getBaseScanPackage() throws IOException {
        return resourceProperties.getProperty(AppConfigConstant.scanPackage);
    }

    private static Properties loadProperties(String filename) throws IOException {
        Properties properties = new Properties();
        InputStream inputStream = null;
        try {
            inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
            if (inputStream == null) {
                throw new FileNotFoundException(filename + " file is not found");
            }
            properties.load(inputStream);
        } finally {
            if (inputStream != null) {
                inputStream.close();
            }
        }
        return properties;
    }
}
